<?php
session_start();
// include settings and functions
include "../conn/database.php";
include "functions.php";

if(isset($_GET['key'])) {
	// initialize errors values
	$errors=0;
	$errors_text = '';
	// cleanning the post data from hacking attempt
	$get_data = clean($_GET);
	
	// empty post data verification
	if(empty($_GET['key'])) {
		$errors_text .= "Des champs sont vides";
		$errors++;
	}
	
	// if no errors we proceed
	if($errors == 0) {
		
		$sql = "SELECT * FROM `R_WEDDINGS_INCHARGE` WHERE ACTIVATE_KEY = '".$get_data['key']."' limit 1";
		$res = mysql_query($sql);
		$rows = mysql_num_rows($res);
		$result = mysql_fetch_array($res);
		
		//if ACTIVATE_KEY exit
		if($rows>0){
			//if it is already actived
			if($result['IS_ACTIVATED']) {
				$errors_text .= "You are already actived";
				$errors++;
			} else {
			}
				//change thIS_ACTIVATEDed stage
				$sql2 = "UPDATE `R_WEDDINGS_INCHARGE`
								SET `IS_ACTIVATED`='1' WHERE ACTIVATE_KEY = '".$get_data['key']."'";
				$res2 = mysql_query($sql2) or die (mysql_error());
				echo('Actived succeed.<a href="../login.php">back</a>');
				//header("Location: ../login.php");
		} else {
			$errors_text .= "Key error.<br />";
			$errors++;
			//header("Location: ../login.php");
		}
	}
}
?>
<!DOCTYPE html>
<html lang="fr">
	<head>

	</head>
	<body>
		<!-- HEADER -->
<?php print_r($errors); ?>
<?php print_r($errors_text); ?>
		<!-- / HEADER -->
	</body>
</html>